from django.http import HttpResponse
from django.shortcuts import render

from django.views.generic import View

from apps.goods.models import Commodityclass


class IndexView(View):
    def get(self, request):
        """
        主页
        :param request:
        :return:
        """
        contents = {}
        contents_categories = Commodityclass.objects.all()
        for i in contents_categories:
            contents[i.name] = i.commodity_set.all()
        # 渲染模板的上下文
        context = {
            'contents': contents,
            'contents_categories':contents_categories
        }
        return render(request, 'index.html', context)
